// web/src/app/learn/(dashboard)/(routes)/teacher/analytics/page.tsx
import React from 'react';
import {currentUser} from "@/lib/auth";
import {redirect} from "next/navigation";
import {getAnalytics} from "@/actions/learn/get-analytics";
import DataCard from "@/app/learn/(dashboard)/(routes)/teacher/analytics/_compnents/data-card";
import Chart from "@/app/learn/(dashboard)/(routes)/teacher/analytics/_compnents/chart";

const Page = async () => {
    const user = await currentUser()
    if (!user) return redirect('/learn')

    const {data, totalSales, totalRevenue}
        = await getAnalytics(user.id!)

    return (
        <div className={`p-6`}>
            <div className={`grid grid-cols-1 md:grid-cols-2 gap-4 mb-4`}>
                <DataCard
                    value={totalRevenue}
                    label={'Total Revenue'}
                    shouldFormat
                />
                <DataCard
                    value={totalSales}
                    label={'Total Sales'}
                />
            </div>
            <Chart data={data}/>
        </div>
    );
};

export default Page;